package com.totcy.atom.presenter;

import android.content.Context;

import com.totcy.atom.bean.SubjectBean;
import com.totcy.atom.model.SubjectModel;
import com.totcy.atom.presenter.contract.SubjectContract;
import com.totcy.baselibrary.base.mvpbase.BasePresenterImpl;

import java.util.List;

public class SubjectPresenter extends BasePresenterImpl<SubjectContract.View, SubjectContract.Model> implements SubjectContract.Presenter {

    public SubjectPresenter(Context context) {
        super(context);
    }

    @Override
    public void getSubjectList() {
        if (isModelAttached()) {
            getModel().getSubjectList( new SubjectContract.Model.DataCallback() {

                @Override
                public void onSubjectList(List<SubjectBean> subjects) {
                    if(isViewAttached()){
                        getView().onSubjectList(subjects);
                    }
                }

                @Override
                public void onDataNotAvailable(int code, String message) {
                    if (isViewAttached()) {
                        getView().onFail(code, message);
                    }
                }
            });
        }
    }

    @Override
    public SubjectContract.Model attachModel() {
        return new SubjectModel(mContext);
    }
}
